package com.dao;

import com.entity.Users;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class UpdateServlet {
    public Connection getConn() throws SQLException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/manger","root","");
    }

    public Users addSql(String username , String password , String email) throws SQLException {
       String sql = "INSERT INTO users values (?,?,?) ";
        QueryRunner queryRunner = new QueryRunner();
        return queryRunner.insert(getConn(), sql, new BeanHandler<>(Users.class), username, password, email);
    }
}
